package com.chunfeng.controller;

import com.chunfeng.entity.Address;
import com.chunfeng.result.JsonRequest;
import com.chunfeng.result.ServiceController;
import com.chunfeng.service.IAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地址Controller
 *
 * @author by 春风能解释
 * <p>
 * 2022/12/20
 */
@RestController
@RequestMapping("/address")
public class AddressController extends ServiceController {

    /**
     * 地址业务层注入
     */
    @Autowired
    private IAddressService addressService;

    /**
     * 查看所有地址信息
     *
     * @return JSON
     */
    @GetMapping
    public JsonRequest<List<Address>> lookAllAddresses() {
        return addressService.lookAllAddresses();
    }

    /**
     * 按条件获取地址信息
     *
     * @param address 条件
     * @return JSON
     */
    @PostMapping("/con")
    public JsonRequest<List<Address>> lookAddressesByCondition(@RequestBody Address address) {
        return addressService.lookAddressesByCondition(address);
    }


    /**
     * 新增一条地址信息
     *
     * @param address 地址信息
     * @return JSON
     */
    @PostMapping
    public JsonRequest<Integer> insertOneAddress(@RequestBody Address address) {
        return addressService.insertOneAddress(address);
    }

    /**
     * 修改一条地址信息
     *
     * @param address 地址信息
     * @return JSON
     */
    @PutMapping
    public JsonRequest<Integer> updateOneAddress(@RequestBody Address address) {
        return addressService.updateOneAddress(address);
    }

    /**
     * 删除地址信息
     *
     * @param ids ID值
     * @return JSON
     */
    @DeleteMapping
    public JsonRequest<Integer> deleteAddress(@RequestBody Integer[] ids) {
        return addressService.deleteAddress(ids);
    }
}
